<meta charset="utf-8">
(#) If the startDestination points to a Class with arguments, the startDestination must be an instance of that class. If it points to a Class without arguments, startDestination can be a KClass literal, such as StartClass::class.

!!! ERROR: If the startDestination points to a Class with arguments, the startDestination must be an instance of that class. If it points to a Class without arguments, startDestination can be a KClass literal, such as StartClass::class.
   This is an error.

Id
:   `WrongStartDestinationType`
Summary
:   If the startDestination points to a Class with arguments, the startDestination must be an instance of that class. If it points to a Class without arguments, startDestination can be a KClass literal, such as StartClass::class.
Severity
:   Error
Category
:   Correctness
Platform
:   Any
Vendor
:   Android Open Source Project
Identifier
:   androidx.navigation.runtime
Feedback
:   https://issuetracker.google.com/issues/new?component=409828
Min
:   Lint 8.0 and 8.1
Compiled
:   Lint 8.7+
Artifact
:   [androidx.navigation:navigation-runtime](androidx_navigation_navigation-runtime.md.html)
Since
:   2.8.0
Affects
:   Kotlin and Java files
Editing
:   This check runs on the fly in the IDE editor
Implementation
:   [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/navigation/navigation-common-lint/src/main/java/androidx/navigation/common/lint/WrongStartDestinationTypeDetector.kt)
Tests
:   [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/navigation/navigation-common-lint/src/test/java/androidx/navigation/common/lint/WrongStartDestinationTypeDetectorTest.kt)
Copyright Year
:   2024

If the startDestination contains arguments, the arguments must be
provided to navigation via a fully formed route (a class instance with
argumentsfilled in), or else it will be treated as a case of missing
arguments.

(##) Example

Here is an example of lint warnings produced by this check:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text
src/com/example/test.kt:8:Error: StartDestination should not be a simple
class name reference.
Did you mean to call its constructor TestClass(...)?
If the class TestClass does not contain arguments,
you can also pass in its KClass reference TestClass::class
[WrongStartDestinationType]
    builder.navigation&lt;TestGraph&gt;(startDestination = TestClass)
                                                     ---------
src/com/example/test.kt:9:Error: StartDestination should not be a simple
class name reference.
Did you mean to call its constructor TestClassWithArg(...)?
If the class TestClassWithArg does not contain arguments,
you can also pass in its KClass reference TestClassWithArg::class
[WrongStartDestinationType]
    builder.navigation&lt;TestGraph&gt;(startDestination = TestClassWithArg)
                                                     ----------------
src/com/example/test.kt:10:Error: StartDestination should not be a
simple class name reference.
Did you mean to call its constructor InnerClass(...)?
If the class InnerClass does not contain arguments,
you can also pass in its KClass reference InnerClass::class
[WrongStartDestinationType]
    builder.navigation&lt;TestGraph&gt;(startDestination = Outer.InnerClass)
                                                     ----------------
src/com/example/test.kt:11:Error: StartDestination should not be a
simple class name reference.
Did you mean to call its constructor InterfaceChildClass(...)?
If the class InterfaceChildClass does not contain arguments,
you can also pass in its KClass reference InterfaceChildClass::class
[WrongStartDestinationType]
    builder.navigation&lt;TestGraph&gt;(startDestination = InterfaceChildClass)
                                                     -------------------
src/com/example/test.kt:12:Error: StartDestination should not be a
simple class name reference.
Did you mean to call its constructor AbstractChildClass(...)?
If the class AbstractChildClass does not contain arguments,
you can also pass in its KClass reference AbstractChildClass::class
[WrongStartDestinationType]
    builder.navigation&lt;TestGraph&gt;(startDestination = AbstractChildClass)
                                                     ------------------
src/com/example/test.kt:13:Error: StartDestination should not be a
simple class name reference.
Did you mean to call its constructor TestInterface(...)?
If the class TestInterface does not contain arguments,
you can also pass in its KClass reference TestInterface::class
[WrongStartDestinationType]
    builder.navigation&lt;TestGraph&gt;(startDestination = TestInterface)
                                                     -------------
src/com/example/test.kt:14:Error: StartDestination should not be a
simple class name reference.
Did you mean to call its constructor TestAbstract(...)?
If the class TestAbstract does not contain arguments,
you can also pass in its KClass reference TestAbstract::class
[WrongStartDestinationType]
    builder.navigation&lt;TestGraph&gt;(startDestination = TestAbstract)
                                                     ------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is the source file referenced above:

`src/com/example/test.kt`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers
package com.example

import androidx.navigation.*

fun createGraph() {
    val provider = NavigatorProvider()
    val builder = NavGraphBuilder(provider, TestGraph, null)
    builder.navigation<TestGraph>(startDestination = TestClass)
    builder.navigation<TestGraph>(startDestination = TestClassWithArg)
    builder.navigation<TestGraph>(startDestination = Outer.InnerClass)
    builder.navigation<TestGraph>(startDestination = InterfaceChildClass)
    builder.navigation<TestGraph>(startDestination = AbstractChildClass)
    builder.navigation<TestGraph>(startDestination = TestInterface)
    builder.navigation<TestGraph>(startDestination = TestAbstract)
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can also visit the
[source code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/navigation/navigation-common-lint/src/test/java/androidx/navigation/common/lint/WrongStartDestinationTypeDetectorTest.kt)
for the unit tests for this check to see additional scenarios.

The above example was automatically extracted from the first unit test
found for this lint check, `WrongStartDestinationTypeDetector.testNavGraphBuilder_classHasError`.
To report a problem with this extracted sample, visit
https://issuetracker.google.com/issues/new?component=409828.

(##) Conflicts

This issue id has also been used by other, unrelated lint checks. Issue
id's must be unique, so you cannot combine these libraries. Also defined
in:
* WrongStartDestinationType: If the startDestination points to a Class with arguments, the startDestination must be an instance of that class. If it points to a Class without arguments, startDestination can be a KClass literal, such as StartClass::class. (this issue)
* [WrongStartDestinationType from androidx.navigation:navigation-compose:2.9.0-alpha04](WrongStartDestinationType.md.html)
* [WrongStartDestinationType from androidx.navigation:navigation-common:2.9.0-alpha04](WrongStartDestinationType-3.md.html)


(##) Including

!!!
   This is not a built-in check. To include it, add the below dependency
   to your project.

```
// build.gradle.kts
implementation("androidx.navigation:navigation-runtime:2.9.0-alpha04")

// build.gradle
implementation 'androidx.navigation:navigation-runtime:2.9.0-alpha04'

// build.gradle.kts with version catalogs:
implementation(libs.navigation.runtime)

# libs.versions.toml
[versions]
navigation-runtime = "2.9.0-alpha04"
[libraries]
# For clarity and text wrapping purposes the following declaration is
# shown split up across lines, but in TOML it needs to be on a single
# line (see https://github.com/toml-lang/toml/issues/516) so adjust
# when pasting into libs.versions.toml:
navigation-runtime = {
    module = "androidx.navigation:navigation-runtime",
    version.ref = "navigation-runtime"
}
```

2.9.0-alpha04 is the version this documentation was generated from;
there may be newer versions available.

[Additional details about androidx.navigation:navigation-runtime](androidx_navigation_navigation-runtime.md.html).
(##) Suppressing

You can suppress false positives using one of the following mechanisms:

* Using a suppression annotation like this on the enclosing
  element:

  ```kt
  // Kotlin
  @Suppress("WrongStartDestinationType")
  fun method() {
     createGraph(...)
  }
  ```

  or

  ```java
  // Java
  @SuppressWarnings("WrongStartDestinationType")
  void method() {
     createGraph(...);
  }
  ```

* Using a suppression comment like this on the line above:

  ```kt
  //noinspection WrongStartDestinationType
  problematicStatement()
  ```

* Using a special `lint.xml` file in the source tree which turns off
  the check in that folder and any sub folder. A simple file might look
  like this:
  ```xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;lint&gt;
      &lt;issue id="WrongStartDestinationType" severity="ignore" /&gt;
  &lt;/lint&gt;
  ```
  Instead of `ignore` you can also change the severity here, for
  example from `error` to `warning`. You can find additional
  documentation on how to filter issues by path, regular expression and
  so on
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).

* In Gradle projects, using the DSL syntax to configure lint. For
  example, you can use something like
  ```gradle
  lintOptions {
      disable 'WrongStartDestinationType'
  }
  ```
  In Android projects this should be nested inside an `android { }`
  block.

* For manual invocations of `lint`, using the `--ignore` flag:
  ```
  $ lint --ignore WrongStartDestinationType ...`
  ```

* Last, but not least, using baselines, as discussed
  [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).

<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script src="https://morgan3d.github.io/markdeep/latest/markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>